package com.fang.unit;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestProvider {
    public static void main(String[] args) throws IOException {
        test01();
        System.out.println("=========================");
        test02();
        System.out.println("=========================");
        test03();
        System.out.println("=========================");
        test04();
        System.out.println("=========================");
        test05();
    }

    /**
     * 普通输入流的运行
     * @throws IOException
     */
    private static void test01() throws IOException {
        FileInputStream file1 = new FileInputStream("xxx.txt");
         int a = file1.read();
         int b = file1.read();
         int c = file1.read();
         int d = file1.read();
         int e = file1.read();
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
        file1.close();
    }

    /**
     * 使用循环引入输入流
     * @throws IOException
     */
    private static void test02() throws IOException {
        FileInputStream file1 = new FileInputStream("xxx.txt");
        int b;
        while((b = file1.read()) != -1){
            System.out.println(b);
        }
        file1.close();
    }

    /**
     * 输出流的使用
     * @throws IOException
     */
    private static void test03() throws IOException {
        FileOutputStream file2 = new FileOutputStream("yyy.txt",true);
        file2.write(100);
        file2.write(101);
        file2.write(102);
        file2.write(99);
        file2.write(98);
        file2.write(97);
        file2.close();
    }
    private static void test04() throws IOException {
        FileOutputStream file1 = new FileOutputStream("yyy.txt");
        file1.write(103);
        file1.close();
    }
    private static void test05() throws IOException {
        FileOutputStream file2 = new FileOutputStream("xxx.txt",true);
        file2.write(100);
        file2.close();
    }
}
